home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 03 - 1987 / 03.10 Oct 87 / blast demo stuff (LSP) / BlastStuff < prev   
Encoding:
Text File  |  1987-09-15  |  5.4 KB  |  203 lines  |  [TEXT/PJMM]

  1. UNIT BlastStuff;
  2.  
  3. INTERFACE
  4.  
  5.     USES
  6.         ROM85;
  7.  
  8.     PROCEDURE BlastIt;
  9.     PROCEDURE Main;    {not needed for MPW}
  10.  
  11. IMPLEMENTATION
  12.  
  13.     PROCEDURE BlastIt;
  14.         CONST
  15.             buffSize = 122; { sound mode takes 2, 20 triplets = 120 bytes }
  16.         VAR
  17.             holeRgn, circleRgn : RgnHandle;
  18.             theEvent : EventRecord;
  19.             stopIt : Boolean;
  20.             whichWindow : WindowPtr;
  21.             thisWindow : WindowPeek;
  22.             i, dur, cnt, minSize, pictWidth, thePart : Integer;
  23.             blastPict : Pichandle;
  24.             anotherRect, circleRect, tempRect : Rect;
  25.             mouseSpot, holeSize, middlePoint : Point;
  26.             wPort, oldPort, tempPort : GrafPtr;
  27.             DeskPattern : ^Pattern;
  28.             crossHairs, oldCursor : Cursor;
  29.             TheCurs : ^Cursor;
  30.             squareWavePtr : SWSynthPtr;
  31.             amp : integer;
  32.  
  33.     BEGIN
  34.  
  35.     { let's set up sounds... }
  36.         squareWavePtr := SWSynthPtr(NewPtr(buffSize));
  37.         squareWavePtr^.mode := swMode; { squarewave mode }
  38.         cnt := 400;
  39.         amp := 150;
  40.  
  41.     { 19 triplets, with decreasing pitch and volume }
  42.         FOR i := 0 TO 18 DO
  43.             WITH squareWavePtr^.triplets[i] DO
  44.                 BEGIN
  45.                     count := cnt;
  46.                     amplitude := amp;
  47.                     duration := 1;
  48.                     cnt := cnt + 60;
  49.                     amp := amp - 8;
  50.                 END;
  51.  
  52.         WITH squareWavePtr^.triplets[19] DO
  53.             BEGIN
  54.                 count := 0;     { quit }
  55.                 amplitude := 0; { making }
  56.                 duration := 0;  { sounds }
  57.             END;
  58.  
  59.     { let's put up our cursor, saving the old one first...}
  60. {      there is no 'GetCursor' call to complement 'SetCursor',}
  61. {      so we have to dip into low memory and steal it }
  62.         TheCurs := pointer($844);
  63.         oldCursor := TheCurs^;
  64.  
  65.     { we need to put data into our cursor variable so we}
  66. {      can do a 'SetCursor' call.  stuffing the data directly}
  67. {      into low memory doesn't work, because the cursor on the}
  68. {      screen wouldn't change until the mouse was moved }
  69.         StuffHex(ptr(@crossHairs), '71C7408140810000');
  70.         StuffHex(ptr(longint(@crossHairs) + 8), '049002A041C17777');
  71.         StuffHex(ptr(longint(@crossHairs) + 16), '41C102A004900000');
  72.         StuffHex(ptr(longint(@crossHairs) + 24), '4081408171C70000');
  73.         StuffHex(ptr(longint(@crossHairs) + 32), '01C0208210840808');
  74.         StuffHex(ptr(longint(@crossHairs) + 40), '07F007F047F177F7');
  75.         StuffHex(ptr(longint(@crossHairs) + 48), '47F107F007F00808');
  76.         StuffHex(ptr(longint(@crossHairs) + 56), '1084208201C00000');
  77.         StuffHex(ptr(longint(@crossHairs) + 64), '00070008');
  78.         SetCursor(crossHairs);
  79.  
  80.     { make the jaggy hole }
  81.         holeRgn := NewRgn;
  82.         OpenRgn;
  83.         MoveTo(250, 180);
  84.         LineTo(260, 226);
  85.         LineTo(230, 252);
  86.         LineTo(260, 242);
  87.         LineTo(232, 278);
  88.         LineTo(270, 242);
  89.         LineTo(286, 304); { basic hole design by Scott Boyd }
  90.         LineTo(278, 234);
  91.         LineTo(306, 242);
  92.         LineTo(278, 244);
  93.         LineTo(314, 196);
  94.         LineTo(270, 216);
  95.         LineTo(250, 180);
  96.         CloseRgn(holeRgn);
  97.  
  98.     { "home" the region, prepare to add a circle to the middle of the hole }
  99.         WITH holeRgn^^.rgnBBox DO
  100.             OffsetRgn(holeRgn, -left, -top);
  101.  
  102.     { calculate the size of the hole and where the middle is }
  103.         WITH holeRgn^^.rgnBBox DO
  104.             BEGIN
  105.                 holeSize.h := right - left;
  106.                 holeSize.v := bottom - top;
  107.                 middlePoint.h := (right - left) DIV 2;
  108.                 middlePoint.v := (bottom - top) DIV 2;
  109.             END;
  110.  
  111.     { figure out what size to make the circle }
  112.         IF holeSize.h > holeSize.v THEN
  113.             minSize := holeSize.h
  114.         ELSE
  115.             minSize := holeSize.v;
  116.  
  117.     { we'll make the circle 40% of the small dimension;}
  118. {          minSize will be the radius of the circle }
  119.         minSize := minSize DIV 5;
  120.         WITH middlePoint DO
  121.             SetRect(circleRect, h - minSize, v - minSize, h + minSize, v + minSize);
  122.  
  123.     { make the circle }
  124.         circleRgn := NewRgn;
  125.         OpenRgn;
  126.         FrameOval(circleRect);
  127.         CloseRgn(circleRgn);
  128.  
  129.     { add the circle to the hole }
  130.         UnionRgn(holeRgn, circleRgn, holeRgn);
  131.  
  132.     { we don't need this any more... }
  133.         DisposeRgn(circleRgn);
  134.  
  135.     { make the window manager port the current port }
  136.         GetPort(oldPort);
  137.         GetWMgrPort(wPort);
  138.         SetPort(wPort);
  139.  
  140.     { ok, setup's all finished... here's the "main loop" }
  141.         stopIt := FALSE;
  142.         REPEAT
  143.  
  144.           { accept only mouseDown events }
  145.             IF GetNextEvent(mDownMask, theEvent) THEN
  146.                 BEGIN
  147.  
  148.                     { figure out where they clicked }
  149.                     thePart := FindWindow(theEvent.where, whichWindow);
  150.  
  151.           { respond only if they click on the content area of a window }
  152.                     IF (thePart = inContent) THEN
  153.                         BEGIN
  154.  
  155.                             { Make some asynchrounous noise }
  156.                             StartSound(Ptr(squareWavePtr), buffSize, NIL);
  157.  
  158.                             mouseSpot := theEvent.where;
  159.  
  160.                             { position the hole centered over the mouse spot }
  161.                             WITH holeRgn^^.rgnBBox DO
  162.                                 OffsetRgn(holeRgn, -left, -top);
  163.                             OffsetRgn(holeRgn, mouseSpot.h - holeSize.h DIV 2, mouseSpot.v - holeSize.v DIV 2);
  164.                             ThisWindow := WindowPeek(whichWindow);
  165.                             { blast a hole in the structure region }
  166.                             DiffRgn(ThisWindow^.contRgn, holeRgn, ThisWindow^.contRgn);
  167.  
  168.                             { blast a hole in the content region }
  169.                             DiffRgn(ThisWindow^.strucRgn, holeRgn, ThisWindow^.strucRgn);
  170.  
  171.                             { calculate and paint all new visible regions  }
  172.                             CalcVisBehind(WindowPeek(whichWindow), holeRgn);
  173.                             PaintBehind(windowPeek(whichWindow), holeRgn);
  174.  
  175.                             { and now, since 'PaintBehind' messes with the port... }
  176.                             SetPort(wPort);
  177.                         END {IF ( thePart = inContent )... }
  178.                     ELSE
  179.                         { didn't click in a window? }
  180.                         stopIt := TRUE;
  181.                 END; {IF GetNextEvent...}
  182.         UNTIL stopIt;
  183.  
  184.   { clean up the hole }
  185.         DisposeRgn(holeRgn);
  186.  
  187.   {  fix the port  }
  188.         SetPort(oldPort);
  189.  
  190.   { put the old cursor back }
  191.         SetCursor(oldCursor);
  192.  
  193.   { get rid of the sound buffer }
  194.         DisposPtr(Ptr(squareWavePtr));
  195.  
  196.     END; {BlastIt}
  197.  
  198.     PROCEDURE Main; {Not needed for MPW}
  199.     BEGIN
  200.         BlastIt;
  201.     END;
  202.  
  203. END.